#!/bin/bash
_fetch(){
cd "$WORKDIR"
for src in ${source[@]} ; do
	if [ -f $CURDIR/$src ] ; then
		info "Copying: $src"
		cp -prfv $CURDIR/$src $WORKDIR/
	elif [ -d $CURDIR/$src ] ; then
		info "Copying: $src"
		cp -prfv $CURDIR/$src $WORKDIR/

	elif echo "$src" | grep "git://" &>/dev/null ; then
		srcloc=$(echo $src | sed "s|^.*git://|git://|g" | sed "s/::.*//g")
		srcname=$(echo $src | sed "s|::git://.*$||g")
		branch=$(echo $src | sed "s|^.*::||g")
		echo $srcloc $srcname $branch
		info "Clonning: $srcloc"
		if [ "$branch" == "" ] ; then
			[ -d "$srcname" ] || git clone $srcloc $srcname
		else
			[ -d "$srcname" ] || git clone $srcloc $srcname -b $branch
		fi
	elif echo "$src" | grep "^git+" &>/dev/null ; then
		srcloc=$(echo $src | sed "s|^git+||g" | sed "s/::.*//g")
		echo $src | grep "::" &>/dev/null && branch=$(echo $src | sed "s|^.*::||g")
		echo $srcloc $srcname $branch
		info "Clonning: $srcloc"
		if [ "$branch" == "" ] ; then
			git clone $srcloc || true
		else
			git clone $srcloc -b $branch || true
		fi
	elif echo "$src" | grep "::http" &>/dev/null ; then
		srcloc=$(echo $src | sed "s|^.*::||g")
		srcname=$(echo $src | sed "s|::http.*$||g")
		echo $srcloc
		info "Downloading: $srcloc"
		wget -c $srcloc -O $srcname
		echo $srcname | grep ".tar.*" && tar -xf $srcname
	else
		info "Downloading: $srcloc"
		wget -c $src -O $(basename $src) || true
		basename $src | grep ".tar.*" && tar -xf $(basename $src) || true
	fi
done
cd "$CURDIR"
}
